using System.Collections.Generic;
using UnityEngine;

public class MobGroup : MonoBehaviour
{
	public bool singleSpawn;

	public List<MobGroupParms> enemies;

	private int _maxChance;

	private void Start()
	{
		List<MobParameters> list = new List<MobParameters>();
		for (int i = 0; i < enemies.Count; i++)
		{
			string text = enemies[i].mob.gameObject.name;
			GameObject gameObject = Object.Instantiate(enemies[i].mob.gameObject);
			gameObject.name = text;
			gameObject.transform.parent = base.transform;
			list.Add(gameObject.GetComponent<MobParameters>());
			MobGroupParms value = default(MobGroupParms);
			value.mob = list[i];
			value.percentChance = enemies[i].percentChance;
			enemies[i] = value;
		}
		CalculateMaxChance();
	}

	public void CalculateMaxChance()
	{
		if (!singleSpawn)
		{
			return;
		}
		_maxChance = 0;
		foreach (MobGroupParms enemy in enemies)
		{
			_maxChance += enemy.percentChance;
		}
	}

	public MobParameters GetSingleMob()
	{
		int num = 0;
		int num2 = 0;
		num = Random.Range(0, _maxChance);
		foreach (MobGroupParms enemy in enemies)
		{
			num2 += enemy.percentChance;
			if (num2 > num)
			{
				return enemy.mob;
			}
		}
		return null;
	}
}
